﻿using System;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

// Token: 0x02000026 RID: 38
public class SandboxManager : MonoBehaviour
{
	// Token: 0x060000AA RID: 170 RVA: 0x0000F630 File Offset: 0x0000D830
	private void Start()
	{
		this.enemySpawns.AddRange(Resources.LoadAll<GameObject>("Enemy"));
		this.weaponSpawns.AddRange(Resources.LoadAll<GameObject>("Weapon"));
		this.spawnText.text = this.enemySpawns[this.enemyIndex].name;
		this.spawnImage.sprite = this.enemySpawns[this.enemyIndex].transform.GetChild(0).GetComponent<SpriteRenderer>().sprite;
		this.spawnImage.SetNativeSize();
	}

	// Token: 0x060000AB RID: 171 RVA: 0x0000F6C4 File Offset: 0x0000D8C4
	public void UpdateSpawnView()
	{
		if (this.browsingEnemies)
		{
			this.spawnText.text = this.enemySpawns[this.enemyIndex].GetComponent<BodyScript>().actualName;
			this.spawnImage.sprite = this.enemySpawns[this.enemyIndex].transform.GetChild(0).GetComponent<SpriteRenderer>().sprite;
			this.spawnImage.SetNativeSize();
			return;
		}
		this.spawnText.text = this.weaponSpawns[this.wepIndex].name;
		this.spawnImage.sprite = this.weaponSpawns[this.wepIndex].GetComponent<SpriteRenderer>().sprite;
		this.spawnImage.SetNativeSize();
	}

	// Token: 0x060000AC RID: 172 RVA: 0x0000F790 File Offset: 0x0000D990
	public void ClearDead()
	{
		Collider2D[] array = Physics2D.OverlapAreaAll(new Vector2(-300f, -300f), new Vector2(300f, 300f));
		List<BodyScript> list = new List<BodyScript>();
		Collider2D[] array2 = array;
		for (int i = 0; i < array2.Length; i++)
		{
			DamageReceiver damageReceiver;
			if (array2[i].TryGetComponent<DamageReceiver>(out damageReceiver) && !list.Contains(damageReceiver.body))
			{
				list.Add(damageReceiver.body);
				if (!damageReceiver.body.alive && GameManager.main.playerBody != damageReceiver.body)
				{
					Object.Destroy(damageReceiver.body.gameObject);
				}
			}
		}
	}

	// Token: 0x060000AD RID: 173 RVA: 0x0000F82F File Offset: 0x0000DA2F
	public void ChangeSpawnTeam(int change)
	{
		this.spawnTeam += change;
		this.teamText.text = this.spawnTeam.ToString();
	}

	// Token: 0x060000AE RID: 174 RVA: 0x0000F858 File Offset: 0x0000DA58
	private void Update()
	{
		if (Input.GetKeyDown(KeyCode.G))
		{
			Collider2D collider2D = Physics2D.OverlapCircle(Camera.main.ScreenToWorldPoint(Input.mousePosition), 0.5f);
			DamageReceiver damageReceiver;
			if (collider2D && collider2D.TryGetComponent<DamageReceiver>(out damageReceiver) && damageReceiver.body != GameManager.main.playerBody)
			{
				damageReceiver.body.gameObject.AddComponent<PlayerInput>();
				damageReceiver.body.gameObject.AddComponent<HealthRegen>().hpPerSec = 2.5f;
				if (BloodDamageUI.main)
				{
					BloodDamageUI.main.body = damageReceiver.body;
					BloodDamageUI.main.playedCorpusSound = false;
					BloodDamageUI.main.lowHealthAudio.Play();
				}
				if (CameraController.main)
				{
					CameraController.main.checkTransform = damageReceiver.body.torso.transform;
				}
				if (MusicManager.main)
				{
					MusicManager.main.body = damageReceiver.body;
				}
				if (damageReceiver.body.GetComponent<AI>())
				{
					Object.Destroy(damageReceiver.body.GetComponent<AI>());
				}
				Object.Destroy(GameManager.main.playerBody.GetComponent<PlayerInput>());
				Object.Destroy(GameManager.main.playerBody.GetComponent<HealthRegen>());
				GameManager.main.playerBody.knockOutTime = 5f;
				GameManager.main.playerBody = damageReceiver.body;
				this.curTeamText.text = "[Your team: " + damageReceiver.body.team + "]";
			}
		}
		if (Input.GetKeyDown(KeyCode.T))
		{
			this.browsingEnemies = !this.browsingEnemies;
			this.UpdateSpawnView();
		}
		if (Input.GetKeyDown(KeyCode.E))
		{
			if (this.browsingEnemies)
			{
				this.enemyIndex++;
				if (this.enemyIndex >= this.enemySpawns.Count)
				{
					this.enemyIndex = 0;
				}
				this.UpdateSpawnView();
			}
			else
			{
				this.wepIndex++;
				if (this.wepIndex >= this.weaponSpawns.Count)
				{
					this.wepIndex = 0;
				}
				this.UpdateSpawnView();
			}
		}
		if (Input.GetKeyDown(KeyCode.Q))
		{
			if (this.browsingEnemies)
			{
				this.enemyIndex--;
				if (this.enemyIndex < 0)
				{
					this.enemyIndex = this.enemySpawns.Count - 1;
				}
				this.UpdateSpawnView();
			}
			else
			{
				this.wepIndex--;
				if (this.wepIndex < 0)
				{
					this.wepIndex = this.weaponSpawns.Count - 1;
				}
				this.UpdateSpawnView();
			}
		}
		if (Input.GetKeyDown(KeyCode.R))
		{
			if (this.browsingEnemies)
			{
				Object.Instantiate<GameObject>(this.enemySpawns[this.enemyIndex], Camera.main.ScreenToWorldPoint(Input.mousePosition), Quaternion.identity).GetComponent<BodyScript>().team = this.spawnTeam.ToString();
			}
			else
			{
				Object.Instantiate<GameObject>(this.weaponSpawns[this.wepIndex], Camera.main.ScreenToWorldPoint(Input.mousePosition), Quaternion.Euler(0f, 0f, Random.Range(0f, 360f)));
			}
		}
		if (Input.GetKeyDown(KeyCode.H))
		{
			this.godMode = !this.godMode;
		}
		if (this.godMode)
		{
			GameManager.main.playerBody.health = GameManager.main.playerBody.maxHealth;
		}
	}

	// Token: 0x04000186 RID: 390
	public List<GameObject> enemySpawns = new List<GameObject>();

	// Token: 0x04000187 RID: 391
	public List<GameObject> weaponSpawns = new List<GameObject>();

	// Token: 0x04000188 RID: 392
	private int wepIndex;

	// Token: 0x04000189 RID: 393
	private int enemyIndex;

	// Token: 0x0400018A RID: 394
	private bool godMode;

	// Token: 0x0400018B RID: 395
	public TextMeshProUGUI spawnText;

	// Token: 0x0400018C RID: 396
	public TextMeshProUGUI teamText;

	// Token: 0x0400018D RID: 397
	public TextMeshProUGUI curTeamText;

	// Token: 0x0400018E RID: 398
	public Image spawnImage;

	// Token: 0x0400018F RID: 399
	private bool browsingEnemies = true;

	// Token: 0x04000190 RID: 400
	private int spawnTeam;
}
